//
//  RegisterViewCtrl.m
//  OrderSys
//
//  Created by JM on 15/10/5.
//  Copyright © 2015年 zjlskj. All rights reserved.
//

#import "RegisterViewCtrl.h"
#import "JMEdietrCell.h"
#import "LabelButtonCell.h"
#import "MJAlertView.h"
//@interface JMEdietrCell (RegisterViewCtrl)
//+ (JMEdietrCell *) cellWithLabelText:(NSString *)aText keyboardType:(UIKeyboardType) aType placeholder:(NSString *)aPlaceHolderText;
//@end
//@implementation JMEdietrCell (RegisterViewCtrl)
//+ (JMEdietrCell *) cellWithLabelText:(NSString *)aText keyboardType:(UIKeyboardType) aType placeholder:(NSString *)aPlaceHolderText; {
//    JMEdietrCell *cell = [JMEdietrCell editerCell];
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.leftLabel.text = aText;
//    cell.leftLabel.adjustsFontSizeToFitWidth = YES;
//    cell.rightEditer.keyboardType = aType;
//    cell.rightEditer.placeholder = aPlaceHolderText;
//    return cell;
//}
//@end

@interface LabelButtonCell (RegisterViewCtrl)
+ (LabelButtonCell *) cellWithLabelText:(NSString *)aText rightImageName:(NSString *) imageName;
@end
@implementation LabelButtonCell (RegisterViewCtrl)
+ (LabelButtonCell *) cellWithLabelText:(NSString *)aText rightImageName:(NSString *) imageName
{
    LabelButtonCell *cell = [LabelButtonCell labelButtonCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.leftLabel.text = aText;
    cell.leftLabel.adjustsFontSizeToFitWidth = YES;
    if (imageName) {
         [cell.rightButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    return cell;
}
@end

@interface RegisterViewCtrl ()
@property(nonatomic,strong)NSMutableArray *cellArray;
@property(nonatomic,strong)NSMutableArray *cell2Array;
@property(nonatomic,strong)LabelButtonCell *cell2;
@property(nonatomic,strong)LabelButtonCell *cell3;
@property(nonatomic,strong)LabelButtonCell *cell4;
@property(nonatomic,strong)LabelButtonCell *cell5;
@property(nonatomic,strong)LabelButtonCell *cell6;
@property(nonatomic,strong)LabelButtonCell *cell7;
@property(nonatomic,strong)LabelButtonCell *cell8;


@end

@implementation RegisterViewCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"车主注册";
    //添加返回
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"返回"
                                                                    style:UIBarButtonItemStyleDone target:self action:@selector(clickBtnReturn:)];
    
    self.navigationItem.rightBarButtonItem = rightButton;

    
    
    
    [self setupTextCells];
    [self setupTextCells2];
//    self.cell2 = [LabelButtonCell cellWithLabelText:@"kkkk" rightImageName:nil];
//    self.cell3 = [LabelButtonCell labelButtonCell];
//    self.cell4 = [LabelButtonCell labelButtonCell];
//    self.cell5 = [LabelButtonCell labelButtonCell];
//    self.cell6 = [LabelButtonCell labelButtonCell];
//    self.cell7 = [LabelButtonCell labelButtonCell];
//    self.cell8 = [LabelButtonCell labelButtonCell];
    
    self.cell2 = [LabelButtonCell cellWithLabelText:@"车主头像图片" rightImageName:nil];
    self.cell3 = [LabelButtonCell cellWithLabelText:@"驾驶证（正本）" rightImageName:nil];
    self.cell4 = [LabelButtonCell cellWithLabelText:@"驾驶证（副本）" rightImageName:nil];
    self.cell5 = [LabelButtonCell cellWithLabelText:@"保险单（交强险）" rightImageName:nil];
    self.cell6 = [LabelButtonCell cellWithLabelText:@"保险单（商业险）" rightImageName:nil];

    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 10, 300, 60);
    [button setTitle:@"注册" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickBtnResigner:) forControlEvents:UIControlEventTouchUpInside];
    self.tableView.tableFooterView = button;
    
}

- (void)clickBtnReturn:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
- (void)clickBtnResigner:(id)sender {
    
    [MJAlertView showAlertViewWithTitle:@"请认真阅读协议" message:@"发觉上课放假啊是开发建设了看法是对方防守杰里科附近阿拉山口飞机拉萨附近的拉什科觉得法拉盛科技法律开始放假啦是发觉上课放假啊是开发建设了看法是对方防守杰里科附近阿拉山口飞机拉萨附近的拉什科觉得法拉盛科技法律开始放假啦是发觉上课放假啊是开发建设了看法是对方防守杰里科附近阿拉山口飞机拉萨附近的拉什科觉得法拉盛科技法律开始放假啦是" clickedButtonBlock:^(NSInteger index) {
        if (index == 0) {
            
        } else {
            [self dismissViewControllerAnimated:YES completion:^{
            }];
        }
        
    } cancelButtonTitle:@"不同意" otherButtonTitles:@"同意",nil];
}

- (void)setupTextCells {
    self.cellArray = [NSMutableArray array];
    JMEdietrCell *editerCell = nil;
    
     editerCell = [JMEdietrCell cellWithLabelText:@"所属公司:" keyboardType:UIKeyboardTypeDefault placeholder:@""];
     [self.cellArray addObject:editerCell];
    
     editerCell = [JMEdietrCell cellWithLabelText:@"车主姓名:" keyboardType:UIKeyboardTypeDecimalPad placeholder:@"请输入车主姓名（必填）"];
     [self.cellArray addObject:editerCell];
    
     editerCell = [JMEdietrCell cellWithLabelText:@"身份证:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@"请输入身份证号（必填）"];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"地址:" keyboardType:UIKeyboardTypeDefault placeholder:@""];
    [self.cellArray addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"详细地址:" keyboardType:UIKeyboardTypeDecimalPad placeholder:@"请输入地址"];
    [self.cellArray addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"Email:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@"请输入Email"];
    [self.cellArray addObject:editerCell];
    editerCell = [JMEdietrCell cellWithLabelText:@"手机号码:" keyboardType:UIKeyboardTypeDefault placeholder:@"请输入手机号码（必填）"];
    [self.cellArray addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"电话号码:" keyboardType:UIKeyboardTypeDecimalPad placeholder:@"请输入电话号码"];
    [self.cellArray addObject:editerCell];
}
- (void)setupTextCells2 {
    self.cell2Array = [NSMutableArray array];
    JMEdietrCell *editerCell = nil;
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车辆号码:" keyboardType:UIKeyboardTypeDefault placeholder:@"请输入车辆号码（必填）"];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车架号:" keyboardType:UIKeyboardTypeDecimalPad placeholder:@"请输入车架号（必填）"];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"号码种类:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@"请输入号码种类（必填）"];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"保险到期时间:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"年检到期时间:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车辆类型:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车辆状态:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车辆长度:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
    
    editerCell = [JMEdietrCell cellWithLabelText:@"车辆吨位:" keyboardType:UIKeyboardTypeASCIICapable placeholder:@""];
    [self.cell2Array addObject:editerCell];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark-datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableViewz{
    return 7;
    
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0)
        return self.cellArray.count;
    if (section == 1)
        return self.cell2Array.count;
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        JMEdietrCell *cell = self.cellArray[indexPath.row];
        NSInteger height = [cell height];
        return height;
    } else if (indexPath.section == 1) {
        JMEdietrCell *cell = self.cell2Array[indexPath.row];
        NSInteger height = [cell height];
        return height;
    }
    return [LabelButtonCell height];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = nil;
    switch (indexPath.section) {
        case 0:
            cell = self.cellArray[indexPath.row];
            break;
        case 1:
            cell = self.cell2Array[indexPath.row];
            break;
        case 2:
            cell = self.cell2;
            break;
        case 3:
            cell = self.cell3;
            break;
        case 4:
            cell = self.cell4;
            break;
        case 5:
            cell = self.cell5;
            break;
        case 6:
            cell = self.cell6;
            break;
        case 7:
            cell = self.cell7;
            break;
        case 8:
            cell = self.cell8;
            break;
            
        default:
            break;
    }
    return cell;
}
#pragma mark-footer header
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return @"车主信息";
            break;
        case 1:
            return @"车辆信息";
            break;
            
        default:
            break;
    }
    return @" ";
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 30;
            break;
        case 1:
            return 30;
            break;
            
        default:
            break;
    }
    return 10;
}

#pragma mark-delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // NSInteger row = indexPath.row;
    
    
    
}

@end
